package com.leonardo.persistenceme.model.persistancehandlers;

import java.io.DataInputStream;
import java.io.DataOutputStream;
import java.io.IOException;

public class StringPersistenceHandler extends PersistenceHandler {

	private static final String controlString = "$#!NULL!#$";
	
	public void persist(Object obj, DataOutputStream stream) throws IOException {
		if(obj == null) {
			stream.writeUTF(controlString);
			return;
		}
		String value = (String) obj;
		stream.writeUTF(value);
	}

	public Object recover(DataInputStream stream) throws IOException {
		String value = stream.readUTF();
		if(controlString.equals(value))
			return null;
		return value;
	}

}
